<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>事物与锁 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="ACID　　原子性（Atomicity）：原子性是指事务是一个不可分割的工作单位，事务中的操作要么全部成功，要么全部失败。比如在同一个事务中的SQL语句，要么全部执行成功，要么全部执行失败　　一致性（Consistency）：事务必须使数据库从一个一致性状态变换到另外一个一致性状态。以转账为例子，A向B转账，假设转账之前这两个用户的钱加起来总共是2000，那么A向B转账之后，不管这两个账户怎么转，">
<meta property="og:type" content="article">
<meta property="og:title" content="事物与锁">
<meta property="og:url" content="http://yoursite.com/2016/01/27/database/13.事务/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="ACID　　原子性（Atomicity）：原子性是指事务是一个不可分割的工作单位，事务中的操作要么全部成功，要么全部失败。比如在同一个事务中的SQL语句，要么全部执行成功，要么全部执行失败　　一致性（Consistency）：事务必须使数据库从一个一致性状态变换到另外一个一致性状态。以转账为例子，A向B转账，假设转账之前这两个用户的钱加起来总共是2000，那么A向B转账之后，不管这两个账户怎么转，">
<meta property="og:updated_time" content="2016-01-29T17:47:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="事物与锁">
<meta name="twitter:description" content="ACID　　原子性（Atomicity）：原子性是指事务是一个不可分割的工作单位，事务中的操作要么全部成功，要么全部失败。比如在同一个事务中的SQL语句，要么全部执行成功，要么全部执行失败　　一致性（Consistency）：事务必须使数据库从一个一致性状态变换到另外一个一致性状态。以转账为例子，A向B转账，假设转账之前这两个用户的钱加起来总共是2000，那么A向B转账之后，不管这两个账户怎么转，">
  
    <link rel="alternative" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  

</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-database/13.事务" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/01/27/database/13.事务/" class="article-date">
  <time datetime="2016-01-27T08:13:00.000Z" itemprop="datePublished">2016-01-27</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/database/">database</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      事物与锁
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="ACID"><a href="#ACID" class="headerlink" title="ACID"></a>ACID</h2><p>　　<strong>原子性</strong>（Atomicity）：原子性是指事务是一个不可分割的工作单位，事务中的操作要么全部成功，要么全部失败。比如在同一个事务中的SQL语句，要么全部执行成功，要么全部执行失败<br>　　<strong>一致性</strong>（Consistency）：事务必须使数据库从一个一致性状态变换到另外一个一致性状态。以转账为例子，A向B转账，假设转账之前这两个用户的钱加起来总共是2000，那么A向B转账之后，不管这两个账户怎么转，A用户的钱和B用户的钱加起来的总额还是2000，这个就是事务的一致性。<br>　　<strong>隔离性</strong>（Isolation）：事务的隔离性是多个用户并发访问数据库时，数据库为每一个用户开启的事务，不能被其他事务的操作数据所干扰，多个并发事务之间要相互隔离。<br>　　<strong>持久性</strong>（Durability）：一个事务一旦被提交，它对数据库中数据的改变就是永久性的，接下来即使数据库发生故障也不应该对其有任何影响<br>　　事务的四大特性中最麻烦的是隔离性，下面重点介绍一下事务的隔离级别</p>
<h2 id="u9694_u79BB_u6027_u5F15_u53D1_u7684_u95EE_u9898"><a href="#u9694_u79BB_u6027_u5F15_u53D1_u7684_u95EE_u9898" class="headerlink" title="隔离性引发的问题"></a>隔离性引发的问题　　</h2><p>　　事务隔离级别：<strong>一个事务</strong>对数据库的修改与<strong>并行的另一个事务</strong>的隔离程度。两个并发事务同时访问数据库表相同的行时，可能存在以下三个问题：</p>
<h4 id="u810F_u8BFB"><a href="#u810F_u8BFB" class="headerlink" title="脏读"></a>脏读</h4><p>　　脏读指<strong>一个事务读取了另外一个事务未提交的数据（同一条数据）</strong>。假设Ａ向Ｂ转帐100元，对应sql语句如下所示<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">update account set money=money+<span class="number">100</span> where name=<span class="string">'B'</span>;    </span><br><span class="line">update account set money=money-<span class="number">100</span>  where name=<span class="string">'A'</span>;</span><br></pre></td></tr></table></figure></p>
<p>　　当第1条sql执行完，第2条还没执行(A未提交时)，如果此时Ｂ查询自己的帐户，就会发现自己多了100元钱。如果A等B走后再回滚，B就会损失100元。　　</p>
<h4 id="u4E0D_u53EF_u91CD_u590D_u8BFB"><a href="#u4E0D_u53EF_u91CD_u590D_u8BFB" class="headerlink" title="不可重复读"></a>不可重复读</h4><p>　　不可重复读指<strong>在一个事务内读取表中的某一行数据，多次读取结果不同</strong>。例如银行想查询A帐户余额，第一次查询A帐户为200元，此时A向帐户内存了100元并提交了，银行接着又进行了一次查询，此时A帐户为300元了。银行两次查询不一致，可能就会很困惑，不知道哪次查询是准的。<br>　　不可重复读和脏读的区别是，<strong>脏读是读取了其他事务未提交的数据</strong>，不可重复读是重新读取了前一事务已提交的数据。<br>　　很多人认为这种情况就对了，无须困惑，当然是后面的为准。我们可以考虑这样一种情况，比如银行程序需要将查询结果分别输出到电脑屏幕和写到文件中，结果在一个事务中针对输出的目的地，进行的两次查询不一致，导致文件和屏幕中的结果不一致，银行工作人员就不知道以哪个为准了。</p>
<h4 id="u865A_u8BFB_28_u5E7B_u8BFB_29"><a href="#u865A_u8BFB_28_u5E7B_u8BFB_29" class="headerlink" title="虚读(幻读)"></a>虚读(幻读)</h4><p>　　虚读(幻读)是指<strong>在一个事务内读取到了别的事务插入的数据</strong>，导致前后读取不一致。<br>　　如丙存款100元未提交，这时银行做报表统计account表中所有用户的总额为500元，然后丙提交了，这时银行再统计发现帐户为600元了，造成虚读。</p>
<h2 id="u4E8B_u52A1_u9694_u79BB_u6027_u8BBE_u7F6E"><a href="#u4E8B_u52A1_u9694_u79BB_u6027_u8BBE_u7F6E" class="headerlink" title="事务隔离性设置"></a>事务隔离性设置</h2><p>　　MySQL数据库共定义了四种隔离级别：<br>　　1. Serializable(串行化)：可避免脏读、不可重复读、虚读情况的发生。<br>　　2. Repeatable read(可重复读)：可避免脏读、不可重复读情况的发生。<br>　　3. Read committed(读已提交)：可避免脏读情况发生。<br>　　4. Read uncommitted(读未提交)：最低级别，以上情况均无法保证。<br>　　查询事务隔离级别：select @@tx_isolation。mysql数据库默认的事务隔离级别是：Repeatable read(可重复读)<br>　　设置事务隔离级别：set transaction isolation level 隔离级别名</p>
<h2 id="u5E38_u7528_u65B9_u6CD5"><a href="#u5E38_u7528_u65B9_u6CD5" class="headerlink" title="常用方法"></a>常用方法</h2><p>Connection.setAutoCommit(false);//开启事务(start transaction)<br>Connection.rollback();//回滚事务(rollback)<br>Connection.commit();//提交事务(commit)</p>
<h2 id="u5B9E_u6218"><a href="#u5B9E_u6218" class="headerlink" title="实战"></a>实战</h2><p>　　下面使用MySQL数据库演示不同隔离级别下的并发问题，需要同时打开两个窗口模拟2个用户并发访问数据库。</p>
<h4 id="u5F53_u628A_u4E8B_u52A1_u7684_u9694_u79BB_u7EA7_u522B_u8BBE_u7F6E_u4E3Aread_uncommitted_u65F6_uFF0C_u4F1A_u5F15_u53D1_u810F_u8BFB_u3001_u4E0D_u53EF_u91CD_u590D_u8BFB_u548C_u865A_u8BFB"><a href="#u5F53_u628A_u4E8B_u52A1_u7684_u9694_u79BB_u7EA7_u522B_u8BBE_u7F6E_u4E3Aread_uncommitted_u65F6_uFF0C_u4F1A_u5F15_u53D1_u810F_u8BFB_u3001_u4E0D_u53EF_u91CD_u590D_u8BFB_u548C_u865A_u8BFB" class="headerlink" title="当把事务的隔离级别设置为read uncommitted时，会引发脏读、不可重复读和虚读"></a>当把事务的隔离级别设置为read uncommitted时，会引发脏读、不可重复读和虚读</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- A窗口</span></span><br><span class="line"><span class="comment">-- 设置A用户的隔离级别为Read uncommitted(即可以读取其他事物未提交的数据)</span></span><br><span class="line"><span class="operator"><span class="keyword">set</span> <span class="keyword">transaction</span> <span class="keyword">isolation</span> <span class="keyword">level</span> <span class="keyword">read</span> uncommitted;</span></span><br><span class="line"><span class="comment">-- 开启事务</span></span><br><span class="line"><span class="operator"><span class="keyword">start</span> <span class="keyword">transaction</span>;</span></span><br><span class="line"><span class="comment">-- 查询A账户中的钱，再转到B窗口进行操作</span></span><br><span class="line"><span class="operator"><span class="keyword">select</span> * <span class="keyword">from</span> <span class="keyword">account</span>;</span></span><br><span class="line"><span class="comment">-- 发现a多了100元，这时候A读到了B未提交的数据（脏读）</span></span><br><span class="line"><span class="operator"><span class="keyword">select</span> * <span class="keyword">from</span> <span class="keyword">account</span></span><br><span class="line"></span><br><span class="line"><span class="comment">-- B窗口</span></span><br><span class="line"><span class="comment">--开启事务</span></span><br><span class="line"><span class="keyword">start</span> <span class="keyword">transaction</span>;</span></span><br><span class="line"><span class="comment">--不要提交，转到A窗口查询</span></span><br><span class="line"><span class="operator"><span class="keyword">update</span> <span class="keyword">account</span> <span class="keyword">set</span> money=money+<span class="number">100</span> <span class="keyword">where</span> <span class="keyword">name</span>=<span class="string">'A'</span>;</span></span><br></pre></td></tr></table></figure>
<h4 id="u628A_u4E8B_u52A1_u7684_u9694_u79BB_u7EA7_u522B_u8BBE_u7F6E_u4E3Aread_committed_u65F6_uFF0C_u4F1A_u5F15_u53D1_u4E0D_u53EF_u91CD_u590D_u8BFB_u548C_u865A_u8BFB_uFF0C_u4F46_u907F_u514D_u4E86_u810F_u8BFB"><a href="#u628A_u4E8B_u52A1_u7684_u9694_u79BB_u7EA7_u522B_u8BBE_u7F6E_u4E3Aread_committed_u65F6_uFF0C_u4F1A_u5F15_u53D1_u4E0D_u53EF_u91CD_u590D_u8BFB_u548C_u865A_u8BFB_uFF0C_u4F46_u907F_u514D_u4E86_u810F_u8BFB" class="headerlink" title="把事务的隔离级别设置为read committed时，会引发不可重复读和虚读，但避免了脏读"></a>把事务的隔离级别设置为read committed时，会引发不可重复读和虚读，但避免了脏读</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- A窗口</span></span><br><span class="line"><span class="operator"><span class="keyword">set</span> <span class="keyword">transaction</span> <span class="keyword">isolation</span> <span class="keyword">level</span> <span class="keyword">read</span> committed;</span></span><br><span class="line"><span class="operator"><span class="keyword">start</span> <span class="keyword">transaction</span>;</span></span><br><span class="line"><span class="comment">-- a帐户是1000元，转到b窗口</span></span><br><span class="line"><span class="operator"><span class="keyword">select</span> * <span class="keyword">from</span> <span class="keyword">account</span>;</span></span><br><span class="line"><span class="comment">-- a帐户多了100，a读到了别的事务提交的数据，两次读取a帐户读到的是不同的结果（不可重复读，对同一条数据的操作）</span></span><br><span class="line"><span class="operator"><span class="keyword">select</span> * <span class="keyword">from</span> <span class="keyword">account</span>;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">-- B窗口</span></span><br><span class="line"><span class="operator"><span class="keyword">start</span> <span class="keyword">transaction</span>;</span></span><br><span class="line"><span class="operator"><span class="keyword">update</span> <span class="keyword">account</span> <span class="keyword">set</span> money=money+<span class="number">100</span> <span class="keyword">where</span> <span class="keyword">name</span>=<span class="string">'aaa'</span>;</span></span><br><span class="line"><span class="comment">-- 转到a窗口，与1中的区别，多了提交事物</span></span><br><span class="line"><span class="operator"><span class="keyword">commit</span>;</span></span><br></pre></td></tr></table></figure>
<h4 id="u628A_u4E8B_u52A1_u7684_u9694_u79BB_u7EA7_u522B_u8BBE_u7F6E_u4E3Arepeatable_read_28mysql_u9ED8_u8BA4_u7EA7_u522B_29_u65F6_uFF0C_u4F1A_u5F15_u53D1_u865A_u8BFB_uFF0C_u4F46_u907F_u514D_u4E86_u810F_u8BFB_u3001_u4E0D_u53EF_u91CD_u590D_u8BFB"><a href="#u628A_u4E8B_u52A1_u7684_u9694_u79BB_u7EA7_u522B_u8BBE_u7F6E_u4E3Arepeatable_read_28mysql_u9ED8_u8BA4_u7EA7_u522B_29_u65F6_uFF0C_u4F1A_u5F15_u53D1_u865A_u8BFB_uFF0C_u4F46_u907F_u514D_u4E86_u810F_u8BFB_u3001_u4E0D_u53EF_u91CD_u590D_u8BFB" class="headerlink" title="把事务的隔离级别设置为repeatable read(mysql默认级别)时，会引发虚读，但避免了脏读、不可重复读"></a>把事务的隔离级别设置为repeatable read(mysql默认级别)时，会引发虚读，但避免了脏读、不可重复读</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- A窗口</span></span><br><span class="line"><span class="operator"><span class="keyword">set</span> <span class="keyword">transaction</span> <span class="keyword">isolation</span> <span class="keyword">level</span> repeatable <span class="keyword">read</span>;</span></span><br><span class="line"><span class="operator"><span class="keyword">start</span> <span class="keyword">transaction</span>;</span></span><br><span class="line"><span class="comment">-- 表有4个记录，转到b窗口</span></span><br><span class="line"><span class="operator"><span class="keyword">select</span> * <span class="keyword">from</span> <span class="keyword">account</span>;</span></span><br><span class="line"><span class="comment">-- 表有5条记录，这时候发生了a读取到另外一个事务插入的数据（虚读）</span></span><br><span class="line"><span class="operator"><span class="keyword">select</span> * <span class="keyword">from</span> <span class="keyword">account</span>;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">-- B窗口</span></span><br><span class="line"><span class="operator"><span class="keyword">start</span> <span class="keyword">transaction</span>;</span></span><br><span class="line"><span class="operator"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">account</span>(<span class="keyword">name</span>,money) <span class="keyword">values</span>(<span class="string">'ggg'</span>,<span class="number">1000</span>);</span></span><br><span class="line"><span class="comment">-- 转到a窗口</span></span><br><span class="line"><span class="operator"><span class="keyword">commit</span>;</span></span><br></pre></td></tr></table></figure>
<h4 id="u5F53_u628A_u4E8B_u52A1_u7684_u9694_u79BB_u7EA7_u522B_u8BBE_u7F6E_u4E3ASerializable_u65F6_uFF0C_u4F1A_u907F_u514D_u6240_u6709_u95EE_u9898"><a href="#u5F53_u628A_u4E8B_u52A1_u7684_u9694_u79BB_u7EA7_u522B_u8BBE_u7F6E_u4E3ASerializable_u65F6_uFF0C_u4F1A_u907F_u514D_u6240_u6709_u95EE_u9898" class="headerlink" title="当把事务的隔离级别设置为Serializable时，会避免所有问题"></a>当把事务的隔离级别设置为Serializable时，会避免所有问题</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- A窗口</span></span><br><span class="line"><span class="operator"><span class="keyword">set</span> <span class="keyword">transaction</span> <span class="keyword">isolation</span> <span class="keyword">level</span> <span class="keyword">Serializable</span>;</span></span><br><span class="line"><span class="operator"><span class="keyword">start</span> <span class="keyword">transaction</span>;</span></span><br><span class="line"><span class="operator"><span class="keyword">select</span> * <span class="keyword">from</span> <span class="keyword">account</span>;</span><span class="comment">--转到b窗口</span></span><br><span class="line"></span><br><span class="line"><span class="comment">-- B窗口</span></span><br><span class="line"><span class="operator"><span class="keyword">start</span> <span class="keyword">transaction</span>;</span></span><br><span class="line"><span class="comment">-- 发现不能插入，只能等待a结束事务才能插入</span></span><br><span class="line"><span class="operator"><span class="keyword">insert</span> <span class="keyword">into</span> <span class="keyword">account</span>(<span class="keyword">name</span>,money) <span class="keyword">values</span>(<span class="string">'ggg'</span>,<span class="number">1000</span>);</span></span><br></pre></td></tr></table></figure>
<h2 id="u8BBE_u7F6E_u4E8B_u52A1_u56DE_u6EDA_u70B9"><a href="#u8BBE_u7F6E_u4E8B_u52A1_u56DE_u6EDA_u70B9" class="headerlink" title="设置事务回滚点"></a>设置事务回滚点</h2><p>在开发中，有时候可能需要手动设置事务的回滚点，在JDBC中使用如下的语句设置事务回滚点<br>Savepoint sp = conn.setSavepoint();<br>Conn.rollback(sp);<br>Conn.commit();//回滚后必须通知数据库提交事务</p>
<h2 id="u8BFB_u5199_u9501"><a href="#u8BFB_u5199_u9501" class="headerlink" title="读写锁"></a>读写锁</h2><p>　　排他锁（写锁）exclusive lock：写锁会阻塞其他的写锁和读锁。<br>　　共享锁（读锁）shared lock：读锁是共享的，是相互不阻塞的。<br>　　写锁有更高的优先级，写锁请求可能会插入到锁队列中读锁的前面，但读锁不能插入到写锁的前面<br>　　死锁：资源请求相互等待，可以设置锁等待超时后放弃锁请求，处理方式不好，目前InnoDB处理方式是将持有最少行级排他锁的事物进行回滚</p>
<h4 id="u9501_u7C92_u5EA6"><a href="#u9501_u7C92_u5EA6" class="headerlink" title="锁粒度"></a>锁粒度</h4><p>　　表锁：开销最小的策略，特定场景中性能良好，如read local表锁支持某些类型的并发写操作<br>　　行级锁：最大程度支持并发处理（存储引擎层实现）</p>
<h4 id="u60B2_u89C2_u9501"><a href="#u60B2_u89C2_u9501" class="headerlink" title="悲观锁"></a>悲观锁</h4><p>　　每次在拿数据的时候都会上锁，这样别人想拿这个数据就会block直到它拿到锁。传统的关系型数据库里边就用到了很多这种锁机制，比如<strong>行锁、表锁、读锁、写锁等，都是在做操作之前先上锁，属于悲观锁</strong>。</p>
<h4 id="u4E50_u89C2_u9501"><a href="#u4E50_u89C2_u9501" class="headerlink" title="乐观锁"></a>乐观锁</h4><p>　　每次去拿数据的时候都认为别人不会修改，所以不会上锁，但是<strong>在更新的时候会判断在此期间别人有没有去更新这个数据</strong>，可以使用版本号等机制。乐观锁适用于多读的应用类型，这样可以提高吞吐量，像数据库如果提供类似于write_condition机制的其实都是提供的乐观锁。在数据进行提交更新的时候，才会对数据的冲突与否进行检测，如果发现冲突了，则让用户返回错误的信息，让用户决定如何去做。</p>
<h2 id="u53C2_u8003_u94FE_u63A5"><a href="#u53C2_u8003_u94FE_u63A5" class="headerlink" title="参考链接"></a>参考链接</h2><p><a href="http://blog.linezing.com/?p=798#nav-2-2" target="_blank" rel="external">http://blog.linezing.com/?p=798#nav-2-2</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2016/01/27/database/13.事务/" data-id="cijzzpvhq00gu1cfsnq61ozbd" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/database/">database</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2016/01/27/database/12.索引结构/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          索引结构
        
      </div>
    </a>
  
  
    <a href="/2016/01/27/database/11.java调用oracle存储过程/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">oracle spatial</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/cache/">cache</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/database/">database</a><span class="category-list-count">13</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/docker/">docker</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gis/">gis</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/git/">git</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/go/">go</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gradle/">gradle</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/groovy/">groovy</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/hadoop/">hadoop</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/java/">java</a><span class="category-list-count">18</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/linux/">linux</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/log/">log</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mongodb/">mongodb</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mq/">mq</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mybatis/">mybatis</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/netty/">netty</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nginx/">nginx</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nio/">nio</a><span class="category-list-count">19</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nodejs/">nodejs</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/redis/">redis</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/rpc/">rpc</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/spring/">spring</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/tomcat/">tomcat</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/zookeeper/">zookeeper</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/杂项/">杂项</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/aop/">aop</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/aspectj/">aspectj</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cache/">cache</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/classloader/">classloader</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/common-loggings/">common-loggings</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/commonjs/">commonjs</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/database/">database</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/dubbo/">dubbo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fastdfs/">fastdfs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gclib/">gclib</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/geohash/">geohash</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gis/">gis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/">go</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gradle/">gradle</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovy/">groovy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/">hadoop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hessisan/">hessisan</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a><span class="tag-list-count">48</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javassist/">javassist</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/kafka/">kafka</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log/">log</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log4j/">log4j</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/logback/">logback</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/map/">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memecached/">memecached</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mina/">mina</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mongodb/">mongodb</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mq/">mq</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mqtt/">mqtt</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mybatis/">mybatis</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/netty/">netty</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/">nginx</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nio/">nio</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nodejs/">nodejs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/postgresql/">postgresql</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/">protobuf</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/proxy/">proxy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/push/">push</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rabbitmq/">rabbitmq</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/">redis</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rpc/">rpc</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sitemesh/">sitemesh</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sld/">sld</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/slf4j/">slf4j</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/socket/">socket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spatialite-for-android/">spatialite for android</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spi/">spi</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spring/">spring</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tomcat/">tomcat</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/transaction/">transaction</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/web/">web</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/xSocket/">xSocket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zbus/">zbus</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zookeeper/">zookeeper</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/数据结构/">数据结构</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/aop/" style="font-size: 15.38px;">aop</a> <a href="/tags/aspectj/" style="font-size: 11.54px;">aspectj</a> <a href="/tags/cache/" style="font-size: 11.54px;">cache</a> <a href="/tags/classloader/" style="font-size: 10px;">classloader</a> <a href="/tags/common-loggings/" style="font-size: 10px;">common-loggings</a> <a href="/tags/commonjs/" style="font-size: 12.31px;">commonjs</a> <a href="/tags/database/" style="font-size: 16.92px;">database</a> <a href="/tags/docker/" style="font-size: 13.85px;">docker</a> <a href="/tags/dubbo/" style="font-size: 10px;">dubbo</a> <a href="/tags/fastdfs/" style="font-size: 10px;">fastdfs</a> <a href="/tags/gclib/" style="font-size: 10.77px;">gclib</a> <a href="/tags/geohash/" style="font-size: 10px;">geohash</a> <a href="/tags/gis/" style="font-size: 10px;">gis</a> <a href="/tags/git/" style="font-size: 10.77px;">git</a> <a href="/tags/go/" style="font-size: 10px;">go</a> <a href="/tags/gradle/" style="font-size: 10px;">gradle</a> <a href="/tags/groovy/" style="font-size: 10px;">groovy</a> <a href="/tags/hadoop/" style="font-size: 10px;">hadoop</a> <a href="/tags/hessisan/" style="font-size: 11.54px;">hessisan</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/javassist/" style="font-size: 10px;">javassist</a> <a href="/tags/kafka/" style="font-size: 11.54px;">kafka</a> <a href="/tags/linux/" style="font-size: 12.31px;">linux</a> <a href="/tags/log/" style="font-size: 17.69px;">log</a> <a href="/tags/log4j/" style="font-size: 12.31px;">log4j</a> <a href="/tags/logback/" style="font-size: 13.08px;">logback</a> <a href="/tags/map/" style="font-size: 10px;">map</a> <a href="/tags/memecached/" style="font-size: 10.77px;">memecached</a> <a href="/tags/mina/" style="font-size: 13.08px;">mina</a> <a href="/tags/mongodb/" style="font-size: 19.23px;">mongodb</a> <a href="/tags/mq/" style="font-size: 13.85px;">mq</a> <a href="/tags/mqtt/" style="font-size: 10.77px;">mqtt</a> <a href="/tags/mybatis/" style="font-size: 16.15px;">mybatis</a> <a href="/tags/netty/" style="font-size: 10px;">netty</a> <a href="/tags/nginx/" style="font-size: 11.54px;">nginx</a> <a href="/tags/nio/" style="font-size: 13.08px;">nio</a> <a href="/tags/nodejs/" style="font-size: 10px;">nodejs</a> <a href="/tags/postgresql/" style="font-size: 10.77px;">postgresql</a> <a href="/tags/protobuf/" style="font-size: 10px;">protobuf</a> <a href="/tags/proxy/" style="font-size: 10px;">proxy</a> <a href="/tags/push/" style="font-size: 10px;">push</a> <a href="/tags/rabbitmq/" style="font-size: 11.54px;">rabbitmq</a> <a href="/tags/redis/" style="font-size: 13.85px;">redis</a> <a href="/tags/rpc/" style="font-size: 19.23px;">rpc</a> <a href="/tags/sitemesh/" style="font-size: 10px;">sitemesh</a> <a href="/tags/sld/" style="font-size: 10px;">sld</a> <a href="/tags/slf4j/" style="font-size: 10px;">slf4j</a> <a href="/tags/socket/" style="font-size: 14.62px;">socket</a> <a href="/tags/spatialite-for-android/" style="font-size: 10px;">spatialite for android</a> <a href="/tags/spi/" style="font-size: 10px;">spi</a> <a href="/tags/spring/" style="font-size: 18.46px;">spring</a> <a href="/tags/tomcat/" style="font-size: 10.77px;">tomcat</a> <a href="/tags/transaction/" style="font-size: 10px;">transaction</a> <a href="/tags/web/" style="font-size: 10px;">web</a> <a href="/tags/xSocket/" style="font-size: 14.62px;">xSocket</a> <a href="/tags/zbus/" style="font-size: 10px;">zbus</a> <a href="/tags/zookeeper/" style="font-size: 10.77px;">zookeeper</a> <a href="/tags/数据结构/" style="font-size: 10.77px;">数据结构</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">January 2016</a><span class="archive-list-count">67</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">December 2015</a><span class="archive-list-count">81</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">November 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2016/01/30/资料/">(no title)</a>
          </li>
        
          <li>
            <a href="/2016/01/30/java/13.Classloader系列一/">ClassLoader系列一</a>
          </li>
        
          <li>
            <a href="/2016/01/29/hadoop/1.hadoop系列之源码编译/">hadoop系列一之源码编译</a>
          </li>
        
          <li>
            <a href="/2016/01/29/go/1.GO系列之入门/">Go系列一之入门</a>
          </li>
        
          <li>
            <a href="/2016/01/28/tomcat/2.tomcat性能优化/">tomcat性能优化</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2016 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

  </div>
</body>
</html>